<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const data = [
        { name: "f", age: "18" },
        { name: "e", age: "19" },
      ];
      const createCompare = (key) => (a, b) => {
        let val1 = a[key],
          val2 = b[key];
        console.log(a);
        console.log(b)[=];
        if (val1 < val2) {
          return -1;
        } else if (val1 > val2) {
          return 1;
        } else {
          return 0;
        }
      };
      // console.log(createCompare("age"));
      data.sort(createCompare("age"));
      // console.log(data[0]);b
      // data.sort(createCompare("name"));
      // console.log(data[0]);
    </script>
  </body>
</html>
